﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Data.SqlClient;
using System.Windows.Forms;
using System.Data.SqlClient;
//using MySql.Data;

namespace SAD
{
    public class Conexion
    {
        public static SqlConnection connection;

        public void AbrirConexion()
        {
            try
            {
                string cadenaConexion = "Server=localhost; Database=dbPrueba; Uid=SADadmin; Pwd=1234";
              
                connection = new SqlConnection(cadenaConexion);
                connection.Open();
                MessageBox.Show("conexion a la base de datos sql server exitosa", "SAD aviso");
            }
            catch (SqlException e)
            {
                //MessageBox.Show(e.ToString());
                MessageBox.Show("falló la conexión a la base de datos, revisa que el id y password en la clase 'conexion.cs' sean los correctos","SAD avisos");
            }
        }

        public void CerrarConexion()
        {
            connection.Close();
        }

        public void EjecutarComando(String consulta)
        {
            SqlCommand command = connection.CreateCommand();
            command.CommandText = consulta;
            command.ExecuteNonQuery();
        }

        public SqlDataReader EjecutarReader(String consulta)
        {
            SqlCommand command = connection.CreateCommand();
            command.CommandText = consulta;
            SqlDataReader dataReader = command.ExecuteReader();
            return dataReader;
        }

        public  string Cadenaconexion(){

            string cadenaConexion = "Server=localhost; Database=dbPrueba; Uid=SADadmin; Pwd=1234";
            return cadenaConexion;
        }
    }
}
